<?php
/**
 * @author qingyu8@staff.weibo.com
 * @date 2018/04/01
 */
namespace api\modules\v1\controllers;

use common\logic\Boat;
use Yii;
use yii\validators\Validator;
use yii\web\Controller;
use yii\web\Response;

class HomeController extends Controller {
    public function beforeAction($action) {
        Yii::$app->response->format = Response::FORMAT_JSON;
        return parent::beforeAction($action);
    }

    public function actionHot() {
        $list = Boat::getHot();
        return [
            'code' => 200,
            'data' => [
                'list' => $list
            ],
        ];
    }

    public function actionRecommendship() {

        return [
            'code' => 200,
            'msg' => 'Recommend Ship',
        ];
    }

    public function actionRecommendboat() {
        $location = Yii::$app->request->get('location');
        $cursor = Yii::$app->request->get('cursor');
        $limit = Yii::$app->request->get('limit');
        $res = Boat::getRecommendBoats($location, $cursor, $limit);
        return [
            'code' => 200,
            'data' => [
                'location' => $res,
            ],
        ];
    }

    public function actionRecommendlocation() {
        return [
            'code' => 200,
            'data' => [
                'list' => json_decode('[{"locationName":"红海","countries":[{"nameZH":"埃及","nameEN":"Egypt"},{"nameZH":"苏丹","nameEN":"Sudan"},{"nameZH":"吉布提","nameEN":"Djibouti"}]},{"locationName":"东南亚","countries":[{"nameZH":"泰国","nameEN":"Thailand"},{"nameZH":"斯米兰群岛","nameEN":"Similan"},{"nameZH":"缅甸","nameEN":"Myanmar"},{"nameZH":"印度尼西亚","nameEN":"Indonesia"},{"nameZH":"科莫多","nameEN":"Komodo"},{"nameZH":"班达海","nameEN":"Banda"}]},{"locationName":"大洋洲","countries":[{"nameZH":"斐济","nameEN":"Viti"},{"nameZH":"法属波利尼西亚","nameEN":"Polynesia"},{"nameZH":"帕劳","nameEN":"Belau"},{"nameZH":"所罗门群岛","nameEN":"Solomon"},{"nameZH":"澳大利亚","nameEN":"Australia"},{"nameZH":"汤加","nameEN":"Tonga"}]}]')
            ]
        ];
    }
}
